#include <iostream>
#include<vector>
#include<string>
using namespace std;

bool checkInvalid(string &str) {
	int size = str.size();
	if (str.size() < 8)
		return false;
	bool digit = false, lower = false, upper = false, symbol = false;
	for (auto &item : str) {
		if (isdigit(item))
			digit = true;
		else if (isupper(item))
			upper = true;
		else if (islower(item))
			lower = true;
		else
			symbol = true;
	}
	int check = digit + lower + upper + symbol;
	if (check < 3)
		return false;
	for (int start = 0; start < size / 2; start++) {
		int subsize = 3;
		while (subsize < size / 2) {
			string substr = str.substr(start, subsize);
			string res = str.substr(start + subsize);
			if (res.find(substr) != -1)
				return false;
			subsize++;
		}
	}
	return true;
}

int main() {
	vector<string> result;
	string str;
	while (cin >> str) {
		string ans;
		if (checkInvalid(str))
			ans = "OK";
		else
			ans = "NG";
		result.push_back(ans);
	}
	for (auto& ele : result)
		cout << ele << endl;

}
